package framework.office.apache.poi.doc;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class docTestutf8 {
	public static void main(String[] args) throws Exception {
		outdoc4();
	}
	public static void indoc1() throws Exception {
		FileInputStream fis = new FileInputStream(new File("1.doc"));
		HWPFDocument di = new HWPFDocument(fis);
		System.out.println(di.getDocumentText());
		System.out.println(di.getText());
		fis.close();
	}
	public static void indoc2() throws Exception {
		HWPFOutputStream hos = new HWPFOutputStream();
	}
	public static void outdoc() throws Exception {
		String filetowrite = "2.doc";
		String content = "测试数据";
		byte[] b = content.getBytes();
		ByteArrayInputStream bais = new ByteArrayInputStream(b);
		POIFSFileSystem fs = new POIFSFileSystem();
		FileOutputStream out = new FileOutputStream(filetowrite);
		fs.writeFilesystem(out);
		bais.close();
		out.close();
	}
	public static void outdoc1() throws Exception {
		String filetowrite = "2.doc";
		String content = "测试数据";
		String utftogbk = new String(content.getBytes(), "gbk");
		byte[] b = utftogbk.getBytes();
		ByteArrayInputStream bais = new ByteArrayInputStream(b);
		POIFSFileSystem fs = new POIFSFileSystem();
		FileOutputStream out = new FileOutputStream(filetowrite);
		fs.writeFilesystem(out);
		bais.close();
		out.close();
	}
	public static void outdoc2() throws Exception {
		String filetowrite = "2.doc";
		String content = "测试数据";
		// String test="濞村鐦弫鐗堝祦";
		// t1=
		byte[] b = content.getBytes();
		String utftogbk = new String(content.getBytes(), "gbk");
		byte[] bu = utftogbk.getBytes();
		File file = new File(filetowrite);
		FileOutputStream fos = new FileOutputStream(file);
		HWPFOutputStream dt = new HWPFOutputStream();
		dt.write(utftogbk.getBytes());
		dt.writeTo(fos);
	}
	public static void outdoc3() throws Exception {
		String filetowrite = "2.doc";
		String content = "测试数据";
		String utftogbk = new String(content.getBytes("utf-8"), "iso8859-1");
		ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes());
		FileOutputStream fos = new FileOutputStream(filetowrite);
		HWPFOutputStream dt = new HWPFOutputStream();
		POIFSFileSystem fs = new POIFSFileSystem();
		DirectoryEntry directoryEntry = fs.getRoot();
		DocumentEntry de = directoryEntry.createDocument("WordDocument", bais);
		fs.writeFilesystem(fos);
		bais.close();
		fos.flush();
		fos.close();
	}
	public static void outdoc4() throws Exception {
		String filetowrite = "2.doc";
		String content = "123";
		// String test="濞村鐦弫鐗堝祦";
		// t1=
		byte[] b = content.getBytes();
		String utftogbk = new String(content.getBytes(), "gbk");
		byte[] bu = utftogbk.getBytes();
		File file = new File(filetowrite);
		FileOutputStream fos = new FileOutputStream(file);
		HWPFOutputStream dt = new HWPFOutputStream();
		dt.write(content.getBytes());
		dt.writeTo(fos);
	}
}
